#include <iostream>
#include <algorithm>
using namespace std;
int coin[6];
int money[] = {500, 100, 50, 10, 5, 1};
int sum = 0;
int main() {
    for (int i = 0; i < 6; i++) 
        cin >> coin[i];
    cin >> sum;
    int result = 0;
    for (int i = 0; i < 6; i++) {
        int x = min(sum / money[i], coin[5 - i]); // 选出合适的数目
        result += x; // 计算总和
        sum -= x * money[i];
        if (sum == 0) break;
    }
    cout << result << endl;
}